'use strict';

const createValidate = {
  section: {
    type: 'string',
    min: 1,
    max: 100,
  },
  url: {
    type: 'string',
    min: 1,
    max: 400,
  },
  title: {
    type: 'string',
    min: 1,
    max: 50,
  },
}

exports.create = async ctx => {
  ctx.validate(createValidate);
  await ctx.service.siteNavigation.create()
  ctx.sendSuccess('ok');
};

exports.update = async ctx => {
  ctx.validate(createValidate);
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.siteNavigation.update());
};

exports.destroy = async ctx => {
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.siteNavigation.destroy(ctx.params.id));
};

